package com.shusl.controller;

import com.shusl.entity.Role;
import com.shusl.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.shusl.web.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 *  控制器
 *
 * @author ikun
 */
@Api(tags = "管理")
@RestController
@RequestMapping("")
public class RoleController{

    private IRoleService roleService;

    @Autowired
    public RoleController(IRoleService roleService){
        this.roleService = roleService;
    }

    @ApiOperation("查询列表")
    @GetMapping("/role/list")
    public PageResult<Role> list(HttpServletRequest request) {
        PageParam<Role> pageParam = new PageParam<>(request);
        return roleService.list(pageParam);
    }

    @ApiOperation("查询单个")
    @GetMapping("/role/read/{id}")
    public JsonResult read(@PathVariable("id") Integer id) {
        return roleService.read(id);
    }

    @ApiOperation("添加")
    @PostMapping("/role/add")
    public JsonResult add(@RequestBody Role model) {
    return roleService.add(model);
    }

    @ApiOperation("修改")
    @PostMapping("/role/update")
    public JsonResult update(@RequestBody Role model) {
    return roleService.update(model);
    }

    @ApiOperation("删除")
    @GetMapping("/role/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        return roleService.delete(ids);
    }

}